<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch"
          data-options="{searchDatagrid:$.CurrentNavtab.find('#purchaseLoan_table')}">
        <fieldset>
            <legend style="font-weight:normal;">条件搜索：</legend>
            <div style="margin:0; padding:1px 15px 15px;">

                <label class="row-label">用户名：</label>
                <input type="text" name="userName" class="form-control" size="15" title="用户名">

                <label class="row-label">&nbsp;双乾标识：</label>
                <input type="text" name="payPlatformID" class="form-control" size="15" title="双乾标识">

                <label class="row-label">&nbsp;标号：</label>
                <input type="text" name="loanNumber" class="form-control" size="15" title="标的编号">

                <label class="row-label">&nbsp;流水号：</label>
                <input type="text" name="orderNo" class="form-control" size="15" title="流水号">

                <label class="row-label">&nbsp;交易时间：</label>
                <input type="text" name="fromTo.from" data-toggle="datepicker" data-nobtn="true" size="11">
                <label class="row-label">-</label>
                <input type="text" name="fromTo.to" data-toggle="datepicker" data-nobtn="true" size="11">

                <label class="row-label"></label>
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="purchaseLoan_table" class="table table-bordered">
    </table>
</div>
<script src="${pageContext.request.contextPath}/js/loan/loanDisplay.js"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/capital/capital.js"></script>
<script type="text/javascript">
    var purchaseLoan_table;
    $(function () {
        purchaseLoan_table = $("#purchaseLoan_table").datagrid({
            height: '100%',
            width: '100%',
            fullGrid : true,
            showToolbar: true,
            filterThead: false,
            delPK: 'id',
            dataUrl: '/admin/capital/loan?_=' + new Date().getTime(),
            local: "remote",
            inlineEditMult: false,
            delConfirm: true,
            saveAll: false,
            addLocation: 'last',
            showTfoot : true,
            postData : {total : "purchaseLoan"},
            toolbarItem: 'refresh,',
            toolbarCustom: function () {
                return '<button type="button" class="btn btn-green" onclick="purchaseLoanExport();" data-icon="sign-out"><i class="fa fa-sign-out"></i> 导出</button>';
            },
            columns: [{
                render: purchaseLoanShowUser,
                label: '用户名',
                align: 'center'
            }, {
                name: 'payPlatformID',
                label: '双乾标识',
                align: 'center'
            }, {
                label: '标的编号',
                align: 'center',
                render: function (value, data) {
                    if (data === undefined) {
                        return '';
                    }
                    return '<a href="javascript:loanInfo(\'' + data.loanId + '\')">' + data.loanNumber + '</a>';
                }
            }, {
                name: 'amount',
                label: '金额',
                align: 'center',
                total:'purchaseLoan'
            }, {
                name: 'date',
                label: '购买日期',
                align: 'center',
                pattern: 'yyyy-MM-dd HH:mm:ss',
                render: function (value) {
                    return value ? value.substr(0, 19) : value
                }
            }, {
                name: 'remark',
                label: '备注',
                align: 'center'
            }, {
                name: 'status',
                label: '交易状态',
                align: 'center',
                items: flowStatus
            }, {
                name: 'orderNo',
                label: '流水号',
                align: 'center'
            }],
            paging: {pageSize: 20, pageIndex: 1},
            linenumberAll: true
        });

        function purchaseLoanShowUser(value, data) {
            return '<a href="javascript:;" onclick="purchaseLoanOpenDialog(\'' + data.userId + "','" + data.userName + '\')">' + data.userName + '</a>';
        }

    });
    function purchaseLoanOpenDialog(id, userName) {
        BJUI.dialog({
            id: 'userInfo_' + id,
            url: '/admin/user/userInfo?id=' + id,
            title: '' + userName + '用户信息',
            width: 1200,
            height: 1200 * 0.618
        });
    }

    function purchaseLoanExport() {
        var dates = $(purchaseLoan_table).data('selectedDatas');
        if (dates && dates.length !== 0) {
            var ids = [];
            dates.forEach(function (e) {
                ids.push(e.id);
            });
            BJUI.ajax('ajaxdownload', {
                url: '/admin/capital/exportLoan',
                data: {ids: ids.join(",")}
            });
        } else
            BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
    }
</script>